package com.study.行为型模式.迭代器模式;

import java.util.Iterator;

public class ComputerCollege implements College{

    Department[] departments;
    int index = 0; //Department类在数组中的下标
    int max = 5;

    public ComputerCollege() {
        this.departments = new Department[max];
        addDepartment("Java专业","Java专业");
        addDepartment("PHP","PHP");
        addDepartment("大数据","大数据");
    }

    @Override
    public String getName() {
        return "计算机学院";
    }

    @Override
    public void addDepartment(String name, String desc) {
        Department department = new Department(name, desc);
        departments[index] = department;
        index++;
    }

    @Override
    public Iterator createIterator() {
        return new ComputerCollegeIterator(departments);
    }
}
